package command;

import human.User;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jdbc.UserDao;

import org.apache.log4j.Logger;

public class MyUserListCommand implements Command {
	private static final Logger log = Logger.getLogger(MyUserListCommand.class.getName());

	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) {
		UserDao userDao = new UserDao();

		String page = null;
		try {
			userDao.close();
			userDao.start();
			HttpSession sess = request.getSession(false);
			Long ownerId = ((Long) sess.getAttribute("userId"));
			ArrayList<User> users = new ArrayList<User>(); 
			users = userDao.selectUsersByOwnerId(ownerId);
		
			request.setAttribute("users", users);
			page = "/myUserList.jspx";
		} finally {
			userDao.close();
		}
		

		return page;
	}

}
